<template>
  <base-layout>
    <template #searchPanel>
      <search-panel
        :selectPer="'111'"
        :excelPer="'newCarOrder:export'"
        @search="search"
        @handleDataExport="handleDataExport"
        :showSearchButton="true"
        :showExportButton="true"
      >
        <el-select
          clearable
          style="width: 150px"
          v-model="searchOptions.businessType"
          placeholder="业务类型"
        >
          <el-option
            v-for="item in businessTypeOptions"
            :key="item"
            :value="item"
            :label="item"
          />
        </el-select>
        <el-input
          v-model="searchOptions.code"
          clearable
          placeholder="收款单号"
          style="width: 150px;margin-bottom: 20px;margin-top: 10px;"
        />
        <!-- <el-select
          clearable
          style="width: 150px"
          v-model="searchOptions.carBrandId"
          placeholder="收款项目"
        >
          <el-option
            v-for="item in getDict(['订单状态'])['订单状态']"
            :key="item.index"
            :value="item.value"
            :label="item.text"
          />
        </el-select> -->
        <el-input
          v-model="searchOptions.licensePlateNumber"
          clearable
          placeholder="车牌号"
          style="width: 150px;margin-bottom: 20px;margin-top: 10px;"
        />
        <el-input
          v-model="searchOptions.receiptObjects"
          clearable
          placeholder="收款对象"
          style="width: 150px;margin-bottom: 20px;margin-top: 10px;"
        />
        <el-input
          v-model="searchOptions.businessCode"
          clearable
          placeholder="业务单号"
          style="width: 150px;margin-bottom: 20px;margin-top: 10px;"
        />
        <el-date-picker
          v-model="searchOptions.receiptDate"
          type="datetimerange"
          start-placeholder="收款开始时间"
          end-placeholder="收款结束时间"
          clearable
          value-format="yyyy-MM-dd HH:mm:ss"
          :default-time="['00:00:00', '23:59:59']"
        />
        <el-date-picker
          v-model="searchOptions.transactionDate"
          type="datetimerange"
          start-placeholder="交易开始时间"
          end-placeholder="交易结束时间"
          clearable
          value-format="yyyy-MM-dd HH:mm:ss"
          :default-time="['00:00:00', '23:59:59']"
        />
      </search-panel>
    </template>
    <template #contentPanel>
      <data-table
        :value="tableData"
        :total-count="totalCount"
        :has-action="true"
        :table-column-attributes="tableColumnAttributes"
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :width="160"
      >
        <template #action="{ row }">
          <i
            class="el-icon-printer cursor"
            title="打印" v-permission="'creditComplete:print'"
            @click="printer(row)"
          ></i>
        </template>
      </data-table>
    </template>
  </base-layout>
</template>
<script>
import baseMixin from '@/mixins/base'
import { receiptRecordList } from '@/api/financial/index'
import { exportFile } from '@/utils/index'
import { CarModel } from '@/components/index'
import { getStoreUser } from '@/api/after-sale/personnel/index'
export default {
  components: {
    CarModel,
  },
  mixins: [
    baseMixin({
      idName: 'id',
      findData: receiptRecordList,
      dataName: ['content', 'totalRecords']
    })
  ],
  data() {
    return {
      getInvoiceId: null,
      modelList: [],
      dataArry: [],
      form: {
        storeId: '',
        client: '' // 客户信息
      },
      tableColumnAttributes: [
        { name: '产生门店', value: 'storeName', type: 'text' },
        { name: '收款单号', value: 'code', type: 'text' },
        { name: '业务类型', value: 'businessType', type: 'text' },
        { name: '客户名称', value: 'customerName', type: 'text' },
        { name: '收款对象', value: 'receiptObjects', type: 'text' },
        { name: '收款项目', value: 'item', type: 'text' },
        { name: '收款描述', value: 'description', type: 'text' },
        { name: '收款方式', value: 'receiptType', type: 'text' },
        { name: '银行简称', value: 'bank', type: 'text' },
        { name: '收款金额', value: 'receivedAmount', type: 'text' },
        { name: 'VIN', value: 'vin', type: 'text' },
        { name: '车牌号', value: 'licensePlateNumber', type: 'text' },
        { name: '业务单号', value: 'businessCode', type: 'text' },
        { name: '收款日期', value: 'receiptDate', type: 'text' },
        { name: '收款人', value: 'receiptPerson', type: 'text' },
        { name: '交易日期', value: 'transactionDate', type: 'text' },
      ],
      businessTypeOptions: ['整车贷款','维修收款','装修收款',
      '整车定金','商品定金','对账收款','整车订单款','销售收款','调拨收款','售后定金','挂账结转']
    }
  },
  methods: {
    // 打印
    printer(row) {
      const { lineId } = row;
      exportFile(`${process.env.BASE_API}/receiptRecord/print/${lineId}`,`收款单.pdf`);
    },
    // 查询
    search() {
      this.currentPage = 1
      this.setTableData()
    },
  },
  async mounted() {
    await getStoreUser().then((res) => {
      const { success, data } = res
      if (success) this.dataArry = data
    })
  }
}
</script>
<style scoped>
  .cursor {
    margin-left: 15px;
    cursor: pointer
  }
</style>
